public class IntegerExpression{
    private ArrayList<Integer> num = new ArrayList<Integer>();
    private String[] operation = {"+", "-", "*", "/"};
    private ArrayList<String> op = new ArrayList<String>();
    private int itemNum;

    public IntegerExpression(int itemNum){
        this.itemNum = itemNum;
        if(itemNum<2)this.itemNum=2;
        else {
            for(int i =0;i < itemNum;i++){
                num.add(initItem());
                if(i>=1){if(op.get(i-1)=="/"){
                    num.set(i-1,num.get(i)*((int)(Math.random()*4+2)));
                    op.add("+");
                }
                else op.add(initOp());
                }
                else op.add(initOp());
            }
        }
    }

    @Override
    public String toString(){
        String s = "";
        for(int i=0;i<itemNum - 1;i++){
            s += num.get(i) + " ";
            s += op.get(i) + " ";
        }
        s += num.get(itemNum-1);
        return s;
    }


    protected String initOp(){
        return operation[(int) (Math.random() * operation.length)];
    }


    protected int initItem(){
        return (int) (Math.random() * 10 + 1);
    }
}
